package adapter;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import utils.Globals;
import utils.Images;
import zq.cn.activity.R;

/**
 * Created by ZQ on 2016/4/23.
 * 为选关界面设置适配器
 */
public class MyAdapter extends BaseAdapter {
    private Context ctx;
    private List<Map<String, Object>> values;

    public MyAdapter(Context ctx, List<Map<String, Object>> values) {
        this.ctx = ctx;
        this.values = values;
    }

    @Override
    public int getCount() {
        return values.size();
    }

    @Override
    public Object getItem(int position) {
        return values.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null) {
            convertView = LayoutInflater.from(ctx).inflate(R.layout.grid_stage, null);
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Globals.SCREEN_HEIGHT/9));
        }

        Map<String, Object> map = values.get(position);
        TextView stageTxt = (TextView) convertView.findViewById(R.id.stage_info);
        stageTxt.setText(map.get("stageTxt").toString());

        if((boolean)map.get("flag")) {
            stageTxt.setBackgroundDrawable(new BitmapDrawable(ctx.getResources(), Images.getSelectBgImg()));
        }else {
            stageTxt.setBackgroundDrawable(new BitmapDrawable(ctx.getResources(), Images.getBgImg()));
        }

        return convertView;
    }
}
